/**
 * Created by python on 19-3-5.
 */
/**
 * Created by python on 19-3-4.
 */
let app = new Vue({
    el: "#app",
    data: {
        // 页面中需要使用到的数据，键值对
        host:HOST,
        label_id:'',//当前标签的id
        qa_content:null,
        token: sessionStorage.token || localStorage.token,
        hotlabel:[],//抬头热门标签
        label:{},//当前标签内容
        questions:[],//当前标签的问题
        server_time:''

    },
    mounted: function () {
            //获取首页后面的热门标签
            axios.get(this.host+'/hotlabels/',{
                //向后端传递JWT token的方法
                headers:{
                    'Authorization':'JWT' + this.token
                },
                responseType:'json',
            })
                .then(response =>{
                    //加载页面数据

                    this.hotlabel = response.data;


                    });
            //获取当前标签的信息
            this.label_id = get_query_string('id');
            axios.get(this.host+'/labels/'+this.label_id+'/',{
                headers:{
                    'Authorization':'JWT' + this.token
                },
                responseType:'json',
            })
                .then(response =>{
                    //加载页面数据
                    this.label = response.data;
                });


                //获取问题
        this.order_way(1)

    },
    methods: {
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
            order_way:function (order) {
                this.order_by = order
                axios.get(this.host+'/labels/questions/?order='+this.order_by+'&label_id='+this.label_id,{
                headers:{
                    'Authorization':'JWT' + this.token
                },
                responseType:'json',
            })
                .then(response=>{
                    this.questions = response.data;
                    this.server_time = response.headers.date;
                });

            }

    },
    computed: {
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    }
});